package ProjectServlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.stream.events.Comment;
import java.awt.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.annotation.ElementType;
import java.security.Signature;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

public class ServletForLog extends HttpServlet {
    ConnectMySql connectMySql ;//ConnectMySql实例
    int id;//房源id
    int surroundId;//周边设施的id
    int communityId;//小区id
    String level;//当前用户的权限等级

    String lgn="";//
    String lat="";//小区id
    String CMU="";//小区id
    List<ProjectServlet.Surrounding>surroundingList = new ArrayList<>();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("get响应");
        String action = req.getParameter("action");
        if(action.equals("login")){
            login(req,resp);
        }
        else if(action.equals("menu1")){
            System.out.println("查询响应");
            Select(req,resp);
        }
        else if(action.equals("singleSelect")){
            singleSelect(req,resp);
        }
        else if(action.equals("table")){
            id=Integer.parseInt(req.getParameter("houseID"));
            findHouseAdr(req,resp,req.getParameter("houseID"));
        }
        else if(action.equals("surroundingServer"))
        {
            showSurrounding(req,resp,id);
        }
        else if(action.equals("multipleSelect"))
        {
            multipleSelect(req,resp);
        }
        else if(action.equals("spaceSelectServer")){
            spaceSelect(req,resp);
        }
        else if(action.equals("findCommunity")){
            surroundId=Integer.parseInt(req.getParameter("spaceBtn"));
            findSurroundCommunity(req,resp,surroundId);
        }
        else if(action.equals("showCommunity")){
            communityId = Integer.parseInt(req.getParameter("communityBtn"));
            ResultSet rs = connectMySql.showCommunityHouse(communityId);
            showHouseMessage(req,resp,rs);

        }
        else if(action.equals("advanceP"))
        {
            RequestDispatcher requestDispatcher = req.getRequestDispatcher("AdvancedPermissions.jsp");
            requestDispatcher.forward(req,resp);
        }
        else if(action.equals("addCommunity")){
            addCommunity(req,resp);
        }
        else if(action.equals("deleteCommunity")){
            findCommunity(req,resp);
        }
        else if (action.equals("deleteConfirm")){
            deleteCommunity(req,resp);
        }
        else if(action.equals("alterCommunity")){
            findCommunity(req,resp);
        }
        else if(action.equals("alterConfirm")){
            alterCommunity(req,resp);
        }
        else if(action.equals("addHouse")){
            addHouse(req,resp);
        }
        else if(action.equals("deleteHouse")){
            findHouse(req,resp);
        }
        else if(action.equals("deleteHouseConfirm")){
            deleteHouse(req,resp);
        }
        else if(action.equals("alterHouse")){
            findHouse(req,resp);
        }
        else if(action.equals("alterHouseConfirm")){
            alterHouse(req,resp);
        }
        else if(action.equals("addUser")){
            addUser(req,resp);
        }
        else if(action.equals("deleteUser")){
            deleteUser(req,resp);
        }
    }

    public void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{

        System.out.println("登录响应");
        connectMySql = new ConnectMySql(req.getParameter("username"),req.getParameter("password"));
        boolean connect =connectMySql.getConnection();
        level = connectMySql.getLevel(req.getParameter("username"),req.getParameter("password"));
        if(connect&&!level.equals("null")){
            System.out.println("level:"+level);
            resp.sendRedirect("http://localhost:63342/web2/web/Menu01.html");
        }
        else {
            resp.setContentType("text/html;charset=UTF-8");
            PrintWriter out = resp.getWriter();
            String title = "错误";
            String doType =  "<!DOCTYPE html> \n";
            out.println(doType+
                    "<html>\n" +
                    "<head><title>"+title+"</title></head>\n" +
                    "<body>\n" +
                    "<h1>登录出现错误！请检查用户名和密码，查看数据库服务是否打开</h1>\n" +
                    "</body>" +
                    "</html>"
            );
        }
    }

    public void Select(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        String btnCondition = req.getParameter("BtnCondition");
        RequestDispatcher requestDispatcher;
        if(btnCondition.equals("空间查询"))
            requestDispatcher = req.getRequestDispatcher("spaceSelect.jsp");
        else
            requestDispatcher =null;

        switch (btnCondition) {
            case "单条件查询" -> resp.sendRedirect("http://localhost:63342/web2/web/singleSelect.html");
            case "多条件查询" -> resp.sendRedirect("http://localhost:63342/web2/web/MultipleSelect.html");
            case "空间查询" -> requestDispatcher.forward(req,resp);
            case "高级权限" ->{
                if(level.equals("visitor")){
                    resp.setContentType("text/html;charset=UTF-8");
                    PrintWriter out = resp.getWriter();
                    String title = "错误";
                    String doType =  "<!DOCTYPE html> \n";
                    out.println(doType+
                            "<html>\n" +
                            "<head><title>"+title+"</title></head>\n" +
                            "<body>\n" +
                            "<h1>你的权限太低！</h1>\n" +
                            "</body>" +
                            "</html>");
                    return;
                }
                requestDispatcher = req.getRequestDispatcher("AdvancedPermissions.jsp");
                req.setAttribute("level",level);
                requestDispatcher.forward(req,resp);
            }
            case "查看小区分布" ->{
                ResultSet rs = connectMySql.selectAllCommunity();
                requestDispatcher=req.getRequestDispatcher("Community.jsp");
                req.setAttribute("communities",rs);
                requestDispatcher.forward(req,resp);
            }
        }
    }

    private void singleSelect(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        System.out.println("单条件查询");
        String inputValue = req.getParameter("inputValue");
        String radio = req.getParameter("singleRadio");
        ResultSet rs =null ;
        switch (radio) {
            case "admA" -> {
                System.out.println(inputValue);
                rs = connectMySql.selectCommunity(inputValue);
            }
            case "houseType" -> {
                System.out.println(inputValue);
                rs = connectMySql.selectHouseType(inputValue);
            }
            case "price" -> {
                System.out.println(inputValue);
                String[] m = inputValue.split(",");
                rs = connectMySql.selectPrice(Double.parseDouble(m[0]), Double.parseDouble(m[1]));
            }
            case "area" -> {
                System.out.println(inputValue);
                String[] m = inputValue.split(",");
                rs = connectMySql.selectArea(Double.parseDouble(m[0]), Double.parseDouble(m[1]));
            }
        }

        showHouseMessage(req,resp,rs);

    }
    private void multipleSelect(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{

        String adm=req.getParameter("AdmA");
        String houseType = req.getParameter("houseType");
        String price = req.getParameter("price");
        String area = req.getParameter("area");
        ResultSet rs = connectMySql.multipleSelect(adm,houseType,price,area);
        showHouseMessage(req,resp,rs);
    }
    private void spaceSelect(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        RequestDispatcher requestDispatcher = req.getRequestDispatcher("spaceSelect.jsp");
        String type =  req.getParameter("spaceSelect");
        String data  =req.getParameter("spaceText");
        int i=0;
        if(type.equals("hospital")) i=1;
        if(type.equals("school"))i=2;
        if(type.equals("other"))i=3;
        ResultSet rs =  connectMySql.spaceSelect(data,i);
        List<ProjectServlet.SpaceName>spaceNames = new ArrayList<>();
        try {
            while (rs.next()){
                SpaceName n;
                if(i>1)
                    n= new SpaceName(rs.getString("name"),rs.getString("id"),rs.getString("type"));
                else
                    n=new SpaceName(rs.getString("name"),rs.getString("id"),"");
                spaceNames.add(n);
            }
            req.setAttribute("space",spaceNames);
            requestDispatcher.forward(req,resp);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    private void showHouseMessage(HttpServletRequest req, HttpServletResponse resp,ResultSet rs) throws ServletException, IOException{
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter out = resp.getWriter();
        String title = "查询结果";
        String doType =  "<!DOCTYPE html> \n";
        out.println(doType+
                "<html>\n" +
                "<head><title>"+title+"</title>" +
                "<style type=\"text/css\">\n" +
                "td {\n" +
                "\tborder: 1px blue solid;\n" +
                "\tmargin: 10px;\n" +
                "\tpadding: 10px;\n" +
                "\ttext-align: center;\n" +
                "}"+
                ".one {\n" +
                "\tbackground-color: rgb(255,255,255);\n" +
                "}\n" +
                "\n" +
                ".two {\n" +
                "\tbackground-color: rgb(100,100,100);\n" +
                "}\n" +
                "\n" +
                ".over {\n" +
                "\tbackground-color: aqua;\n" +
                "}\n" +
                "</style>"+
                "<script type=\"text/javascript\">\n" +
                "window.onload = function() {\n" +
                "var trs = document.getElementsByTagName(\"tr\");\n" +
                "for (var i = 1; i < trs.length; i++){\n" +
                "var oldClass = \"\";\n" +
                "trs[i].onmouseover = function(){\n" +
                "oldClass = this.className;\n" +
                "this.className = \"over\";\n" +
                "}\n" +
                "trs[i].onmouseout = function() {\n" +
                "this.className = oldClass;\n" +
                "}\n" +
                "}\n" +
                "\t}\n" +
                "</script>"+
                "</head>\n" +
                "<body>\n" +
                "<h1 align=\"center\">结果显示</h1>\n" +
                "<form action=\"http://localhost:8081/web2_war_exploded/servletForLog\" method=\"get\" target=\"_blank\">" +
                "<input type=\"hidden\" name=\"action\" value=\"table\"/>\n"+
                "<table align=\"center\" border=\"1\"" +
                "<tr>" +
                "<th>id</th>\n"+
                "<th>户型</th>\n"+
                "<th>总价</th>\n"+
                "<th>均价</th>\n"+
                "<th>建筑面积</th>\n"+
                "<th>室内面积:</th>\n"+
                "<th>朝向</th>\n"+
                "<th>所在小区</th>\n"+
                "<th>所在行政区</th>\n"+
                "<th>所在楼层</th>\n"+
                "<th>楼栋总楼层</th>\n"+
                "<th>建筑年份</th>\n"+
                "<th>建筑类型</th>\n"+
                "<th>点击查看详情</th>\n"+
                "</tr>"
        );
        try {
            int count=0;
            while (rs.next()){
                count++;
                String id = rs.getString("id");
                out.println("<tr>" +
                        "<td>"+id+"</td>" +
                        "<td>"+rs.getString("houseType")+"</td>"+
                        "<td>"+rs.getString("totalPrice")+"</td>"+
                        "<td>"+rs.getString("averagePrice")+"</td>"+
                        "<td>"+rs.getString("allArea")+"</td>"+
                        "<td>"+rs.getString("insideArea")+"</td>"+
                        "<td>"+rs.getString("forward")+"</td>"+
                        "<td>"+rs.getString("community")+"</td>"+
                        "<td>"+rs.getString("adm_region")+"</td>"+
                        "<td>"+rs.getString("Hfloor")+"</td>"+
                        "<td>"+rs.getString("totalFloor")+"</td>"+
                        "<td>"+rs.getString("years")+"</td>"+
                        "<td>"+rs.getString("types")+"</td>"+
                        "<td> <input type=\"submit\" name=\"houseID\" value=\""+id+ "\"></td>"+
                        "</tr>\n"
                );


            }
            if (count==0){
                out.println("<h2 align=\"center\">没有数据</h2>");
            }

            out.println("</table>\n</form>\n</body>\n</html>");

        }catch (Exception e){
            e.printStackTrace();
        }

    }
    public void showSurrounding(HttpServletRequest req, HttpServletResponse resp,int id) throws ServletException, IOException{

        RequestDispatcher requestDispatcher = req.getRequestDispatcher("lqb.jsp");

        boolean isHospital=false;
        ResultSet rs = null;
        String surround = req.getParameter("surround");
        switch (surround) {
            case "交通设施" -> rs = connectMySql.findSurroundingTraffic(id);
            case "公共设施" -> rs = connectMySql.findSurroundingPublic(id);
            case "餐饮服务" -> rs = connectMySql.findSurroundingCater(id);
            case "购物服务" -> rs = connectMySql.findSurroundingShop(id);
            case "生活服务" -> rs = connectMySql.findSurroundingLifeServer(id);
            case "风景名胜" -> rs = connectMySql.findSurroundingScenery(id);
            case "附近学校" -> rs = connectMySql.findSurroundSchool(id);
            case "附近医院" -> {
                rs = connectMySql.findSurroundHospital(id);
                isHospital = true;
            }
        }
        surroundingList.clear();
        try {
            while (rs.next()){
                String name= rs.getString("any_value(name)");
                String longitude=rs.getString("any_value(longitude)");
                String latitude = rs.getString("any_value(latitude)");
                String adr=" ";
                if(!isHospital){
                    adr = rs.getString("any_value(`type`)");
                }
                int  d =rs.getInt("distance");

                String distance = Integer.toString(d);
                Surrounding s = new Surrounding(adr,name,distance,longitude,latitude);
                surroundingList.add(s);
            }
            req.setAttribute("surround",surroundingList);
            req.setAttribute("longitude",lgn);
            req.setAttribute("latitude",lat);
            req.setAttribute("community",CMU);
            System.out.println(lgn+" "+lat+" "+CMU);
            requestDispatcher.forward(req,resp);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public void findSurroundCommunity(HttpServletRequest req, HttpServletResponse resp,int id) throws ServletException, IOException{

        RequestDispatcher requestDispatcher = req.getRequestDispatcher("spaceSelect.jsp");
        ResultSet rs = connectMySql.findSurroundCommunity(id);
        List<ProjectServlet.Community> communities = new ArrayList<>();
        try {
            while (rs.next()){
                String cid = rs.getString("any_value(id)");
                String cname=rs.getString("any_value(name)");
                String adm = rs.getString("any_value(adm_region)");
                int dst = rs.getInt("distance");
                String distance = Integer.toString(dst);
                Community c = new Community(cname,adm,cid,distance);
                communities.add(c);
            }
            req.setAttribute("community",communities);
            requestDispatcher.forward(req,resp);
        }catch (Exception e){
            e.printStackTrace();
        }
        requestDispatcher.forward(req,resp);
    }

    public void addCommunity(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{

        RequestDispatcher requestDispatcher = req.getRequestDispatcher("AdvancedPermissions.jsp");
        String[] value = new String[9];
        value[0] = req.getParameter("name");
        value[1] = req.getParameter("longitude");
        value[2] = req.getParameter("latitude");
        value[3] = req.getParameter("adm");
        value[4] = req.getParameter("saleState");
        value[5] = req.getParameter("type");
        value[6] = req.getParameter("price");
        value[7] = req.getParameter("col");
        value[8] = req.getParameter("greening");

         if(connectMySql.addCommunity(value)){
             String isSuccess="增加成功";
             req.setAttribute("message", isSuccess);
             requestDispatcher.forward(req,resp);
         }else{
             String isSuccess="增加失败";
             req.setAttribute("message", isSuccess);
             requestDispatcher.forward(req,resp);
         }



    }

    public void addHouse(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        RequestDispatcher requestDispatcher = req.getRequestDispatcher("AdvancedPermissions.jsp");
        String[] value = new String[11];
        value[0] = req.getParameter("houseType");
        value[1] = req.getParameter("totalPrice");
        value[2] = req.getParameter("averagePrice");
        value[3] = req.getParameter("allArea");
        value[4] = req.getParameter("insideArea");
        value[5] = req.getParameter("forward");
        value[6] = req.getParameter("community");
        value[7] = req.getParameter("Hfloor");
        value[8] = req.getParameter("totalFloor");
        value[9] = req.getParameter("years");
        value[10] = req.getParameter("types");

        if(connectMySql.addHouse(value)){
            String isSuccess="增加成功";
            req.setAttribute("message", isSuccess);
            requestDispatcher.forward(req,resp);
        }else{
            String isSuccess="增加失败";
            req.setAttribute("message", isSuccess);
            requestDispatcher.forward(req,resp);
        }

    }

    public void findCommunity(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        String action = req.getParameter("action");
        if(action.equals("deleteCommunity")){
            String deleteId = req.getParameter("deleteId");
            RequestDispatcher requestDispatcher = req.getRequestDispatcher("AdvancedPermissions.jsp");
            ResultSet rs = connectMySql.findCommunityById(deleteId);
            req.setAttribute("communityRsForDelete",rs);
            requestDispatcher.forward(req,resp);
        }
        if(action.equals("alterCommunity")){
            String alterId = req.getParameter("alterId");
            RequestDispatcher requestDispatcher = req.getRequestDispatcher("AdvancedPermissions.jsp");
            ResultSet rs = connectMySql.findCommunityById(alterId);
            req.setAttribute("communityRsForAlter",rs);
            requestDispatcher.forward(req,resp);
        }

    }

    public void findHouse(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{

        String action = req.getParameter("action");
        if(action.equals("deleteHouse")){
            String deleteId = req.getParameter("deleteId");
            RequestDispatcher requestDispatcher = req.getRequestDispatcher("AdvancedPermissions.jsp");
            ResultSet rs = connectMySql.findHouseById(deleteId);
            req.setAttribute("HouseRsForDelete",rs);
            requestDispatcher.forward(req,resp);
        }
        if(action.equals("alterHouse")){
            String alterId = req.getParameter("alterId");
            RequestDispatcher requestDispatcher = req.getRequestDispatcher("AdvancedPermissions.jsp");
            ResultSet rs = connectMySql.findHouseById(alterId);
            req.setAttribute("HouseRsForAlter",rs);
            requestDispatcher.forward(req,resp);
        }

    }

    public void findHouseAdr(HttpServletRequest req, HttpServletResponse resp, String id) throws ServletException, IOException{
        ResultSet rs =connectMySql.findHousePoint(id);
        RequestDispatcher requestDispatcher = req.getRequestDispatcher("lqb.jsp");
        try {
            while (rs.next()){
               lgn=rs.getString("longitude");

               lat=rs.getString("latitude");

               CMU = rs.getString("community");
            }
            req.setAttribute("surround",surroundingList);
            req.setAttribute("longitude",lgn);
            req.setAttribute("latitude",lat);
            req.setAttribute("community",CMU);
            System.out.println(lgn+" "+lat+" "+CMU);
            requestDispatcher.forward(req,resp);
        }catch (Exception e){

            e.printStackTrace();
        }
    }

    public void deleteHouse(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        String deleteId = req.getParameter("deleteHouseSubmit");
        RequestDispatcher requestDispatcher = req.getRequestDispatcher("AdvancedPermissions.jsp");
        if(connectMySql.deleteHouse(deleteId)){
            String isSuccess="删除成功";
            req.setAttribute("message", isSuccess);
            requestDispatcher.forward(req,resp);
        }else{
            String isSuccess="删除失败";
            req.setAttribute("message", isSuccess);
            requestDispatcher.forward(req,resp);
        }
    }
    public void deleteCommunity(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        String deleteId = req.getParameter("deleteSubmit");
        RequestDispatcher requestDispatcher = req.getRequestDispatcher("AdvancedPermissions.jsp");
        if(connectMySql.deleteCommunity(deleteId)){
            String isSuccess="删除成功";
            req.setAttribute("message", isSuccess);
            requestDispatcher.forward(req,resp);
        }else{
            String isSuccess="删除失败";
            req.setAttribute("message", isSuccess);
            requestDispatcher.forward(req,resp);
        }

    }

    public void alterHouse(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{

        RequestDispatcher requestDispatcher = req.getRequestDispatcher("AdvancedPermissions.jsp");
        String[] newValue = new String[11];
        String[] attribute = new String[]{"houseType","totalPrice","averagePrice","allArea","insideArea","forward","community",
                "Hfloor","totalFloor","years","types"};

        String alterId = req.getParameter("alterSubmitHouse");
        newValue [0] = req.getParameter("houseTypeNew");
        newValue [1] = req.getParameter("totalPriceNew");
        newValue [2] = req.getParameter("averagePriceNew");
        newValue [3] = req.getParameter("allAreaNew");
        newValue [4] = req.getParameter("insideAreaNew");
        newValue [5] = req.getParameter("forwardNew");
        newValue [6] = req.getParameter("communityNew");
        newValue [7] = req.getParameter("HfloorNew");
        newValue [8] = req.getParameter("totalFloorNew");
        newValue [9] = req.getParameter("yearsNew");
        newValue [10] = req.getParameter("typesNew");

        int count=0;
        for(int i=0;i<11;i++){
            if(!newValue[i].isEmpty()){
                if(connectMySql.alterHouse(attribute[i],alterId,newValue[i]))
                    count++;
            }
        }
        String isSuccess="成功修改"+count+"项";
        req.setAttribute("message", isSuccess);
        requestDispatcher.forward(req,resp);
    }
    public void alterCommunity(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{


        RequestDispatcher requestDispatcher = req.getRequestDispatcher("AdvancedPermissions.jsp");
        String[] newValue = new String[9];
        String[] attribute = new String[]{"name","longitude","latitude","adm_region","sale_state","type","price",
                "volume_fraction","greening_rate"};
        String alterId = req.getParameter("alterSubmit");
//        ResultSet rs = connectMySql.findCommunityById(alterId);
//        String[] oldValue = new String[9];
//        try {
//            while (rs.next()){
//                oldValue[0] = rs.getString("name");
//                oldValue[1] = rs.getString("longitude");
//                oldValue[2] = rs.getString("latitude");
//                oldValue[3] = rs.getString("adm_region");
//                oldValue[4] = rs.getString("sale_state");
//                oldValue[5] = rs.getString("type");
//                oldValue[6] = rs.getString("price");
//                oldValue[7] = rs.getString("volume_fraction");
//                oldValue[8] = rs.getString("greening_rate");
//            }
//        }catch (Exception e){
//            e.printStackTrace();
//        }
        newValue [0] = req.getParameter("nameNew");
        newValue [1] = req.getParameter("longitudeNew");
        newValue [2] = req.getParameter("latitudeNew");
        newValue [3] = req.getParameter("admNew");
        newValue [4] = req.getParameter("saleStateNew");
        newValue [5] = req.getParameter("typeNew");
        newValue [6] = req.getParameter("priceNew");
        newValue [7] = req.getParameter("colNew");
        newValue [8] = req.getParameter("greenNew");

        int count=0;
        for(int i=0;i<9;i++){
            if(!newValue [i].isEmpty()){
                if(connectMySql.alterCommunity(attribute[i],alterId,newValue[i]))
                count++;
            }
        }
        String isSuccess="成功修改"+count+"项";
        req.setAttribute("message", isSuccess);
        requestDispatcher.forward(req,resp);

    }

    public void addUser(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{


        RequestDispatcher requestDispatcher = req.getRequestDispatcher("AdvancedPermissions.jsp");
        if(!level.equals("administrator")){
            String isSuccess="你的权限太低";
            req.setAttribute("message", isSuccess);
            requestDispatcher.forward(req,resp);
            return;
        }
        String name=req.getParameter("userName");
        String password =req.getParameter("passWord");
        String level=req.getParameter("userLevel");
        if(connectMySql.addUser(name,password,level)){
            String isSuccess="增加成功";
            req.setAttribute("message", isSuccess);
            requestDispatcher.forward(req,resp);
        }else{
            String isSuccess="增加失败,可能是出现了重复用户名";
            req.setAttribute("message", isSuccess);
            requestDispatcher.forward(req,resp);
        }

    }

    public void deleteUser(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{


        RequestDispatcher requestDispatcher = req.getRequestDispatcher("AdvancedPermissions.jsp");
        String name = req.getParameter("userName");
        if(connectMySql.deleteUser(name)){
            String isSuccess="删除成功";
            req.setAttribute("message", isSuccess);
            requestDispatcher.forward(req,resp);
        }else{
            String isSuccess="删除失败";
            req.setAttribute("message", isSuccess);
            requestDispatcher.forward(req,resp);
        }
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("销毁");
    }

    @Override
    public void destroy() {
        super.destroy();
    }

    public static void main(String[] arg)
    {
        ConnectMySql connectMySql = new ConnectMySql("root","lishunlin");
        connectMySql.selectCommunity("星悦湾");
    }
}
